package cn.wolfcode.wms.util;

import cn.wolfcode.wms.domain.Employee;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpSession;
import java.util.List;

public class UserContext {
    private static HttpSession getSessionBySpring(){
        ServletRequestAttributes requestAttributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
        return requestAttributes.getRequest().getSession();
    }
    public static void setEmployee(Employee employee){
        getSessionBySpring().setAttribute("emp_in_session",employee);
    }
    public static Employee getEmployee(){
        return (Employee) getSessionBySpring().getAttribute("emp_in_session");
    }
//    将登录用户的权限存入session中;
    public static void setExpression(List<String> expressions){
        getSessionBySpring().setAttribute("exp_in_session",expressions);
    }
    public static List<String> getExpression(){
        return (List<String>)getSessionBySpring().getAttribute("exp_in_session");
    }
}
